<%@page import="myJDBC.lowLevel.Attributes"%>
<%@page import="myJDBC.lowLevel.AttributeTypes"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="ISO-8859-1"%>
 <%@page import="myJDBC.lowLevel.Objects"%>
<%@page import="myJDBC.lowLevel.ObjectTypes"%>
<%@page import="myJDBC.*"%>
<%@ page import="java.util.*"%>
<%@page import="myJDBC.lowLevel.Params"%>
<%@page import="myJDBC.lowLevel.References"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>
<%@include file="smallJsps/styles.jsp" %>
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%@include file="smallJsps/bootstrapInclude.jsp" %>
</head>
<body>
<%@include file="smallJsps/logoutButton.jsp" %>
<div class="row-fluid">
		<div class="span6 offset2">
	<%
	int objId = -1;
	if(request.getParameter("objId")!=null)
		objId=Integer.parseInt(request.getParameter("objId"));
	else{
	//	response.sendRedirect("http://www.whatever.com/myJSPFile.jsp");
	}	
	int objTypeId=Integer.parseInt(Objects.returnObjectTypeId(objId));
		ArrayList<String> listWithAttributes2 = ObjectTypes.returnObjectType(objTypeId);
		int barier = listWithAttributes2.indexOf(null);		
	ArrayList<String> alnamedesc= new ArrayList<String>();
	alnamedesc=Objects.returnObjInfo(objId);
	ArrayList<String> parinf= new ArrayList<String>();
	if(!alnamedesc.get(3).equals("0"))
		parinf=Objects.returnObjInfo(Integer.parseInt(alnamedesc.get(3)));
	%>
	<h3>Object info</h3>
	<table class="table table-striped table-condensed" border="3">
		<tr><td><b>name</b></td><td><%=alnamedesc.get(0)%></td></tr>
		<tr><td><b>decription</b></td><td><%=alnamedesc.get(1)%></td></tr>
		<tr><td><b>object type</b></td><td><%=alnamedesc.get(2)%></td></tr>
		<%if(parinf.size()!=0){ %>
		<tr><td><b>parent</b></td><td><a href="workinJsp?objId=<%=alnamedesc.get(3)%>"><% 
		out.print(parinf.get(2)+" || "+parinf.get(0)+" || "+parinf.get(1)); 
		}		%></a></td></tr>
	</table>
	<h3>Parametres</h3>
	<table class="table table-striped table-condensed" border="3">
		<tr>
			<th>name</th>
			<th>value</th>
		</tr>
		<%
			ArrayList<ArrayList<String>> params = new ArrayList<ArrayList<String>>();
			params= Params.retParams(objId);//varch list date val
			for(int i=0;i<params.get(0).size(); i+=2){//id value   
				int attrId=Integer.parseInt(params.get(0).get(i));
				out.print("<tr><td>" + Attributes.returnAttribute(attrId).get(1));
				out.print("</td><td>" + Params.returnVarchNumb(attrId, objId));	
			}
			for(int i=0;i<params.get(1).size(); i+=2){//id value   
				int attrId=Integer.parseInt(params.get(1).get(i));
				out.print("<tr><td>" + Attributes.returnAttribute(attrId).get(1));
				out.print("</td><td>" + Params.returnArrValue(attrId, objId));	
			}
			for(int i=0;i<params.get(2).size(); i+=2){//id value   
				int attrId=Integer.parseInt(params.get(2).get(i));
				out.print("<tr><td>" + Attributes.returnAttribute(attrId).get(1));
				out.print("</td><td>" + Params.returnDate(attrId, objId));	
			}
			for(int i=0;i<params.get(3).size(); i+=2){//id value   
				int attrId=Integer.parseInt(params.get(3).get(i));
				out.print("<tr><td>" + Attributes.returnAttribute(attrId).get(1));
				out.print("</td><td>" + Params.returnDate(attrId, objId));	
			}
			//refs
			ArrayList<Integer> refs= new ArrayList<Integer>();
			refs= References.retRefereces(objId);
			for(int i=0;i<refs.size(); i+=2){//id value   
				int attrId=refs.get(i);
				out.print("<tr><td>" + Attributes.returnAttribute(attrId).get(1));
				out.print("</td><td><a href=\"workinJsp?objId="+ refs.get(i+1)+"\">" + Objects.returnObjInfo(refs.get(i+1)).get(0)+"</a>");
			}
			out.print("</td></tr>");
			
		%>
	</table>
	<%
		ArrayList<Integer> child= new ArrayList<Integer>();
		child=Objects.returnChildrens(objId);
		if(child.size()!=0){
	%>
	<h3>Childs</h3>
	<table class="table table-striped table-condensed" border="3">
		<tr>
			<th>name</th>
			<th>descr</th>
			<th>obj type</th>
		</tr>
	<%
		ArrayList<String> onechild= new ArrayList<String>();
		for(Integer chId:child){
			onechild=Objects.returnObjInfo(chId);
			//<a href=\"workinJsp?objId="+onechild.get(3)+">>" + onechild.get(1)+ "</a><tr><td><a href=\"workinJsp?objId="+onechild.get(3)+">>" + onechild.get(2)+"</a></td></tr>
			out.print("<tr><td><a href=\"workinJsp?objId="+ Integer.toString(chId)+"\">" + onechild.get(0)+ "</a></td>");
			out.print("<td>" + onechild.get(1)+ "</td>");
			out.print("<td>" + onechild.get(2)+ "</td></tr>");
		}
		out.print("</table>");
		}
	 %>
	 <% 
		ArrayList<Integer> ref = new ArrayList<Integer>();
		ref=References.returnLinksOnObj(objId);
		if(ref.size()!=0){
	 %>
	<h3>Links to this object</h3>
	<table class="table table-striped table-condensed" border="3">
		<tr>
			<th>name</th>
			<th>descr</th>
			<th>obj type</th>
		</tr>
		<%
			for(Integer chId:ref){
			ArrayList<String> onechild= new ArrayList<String>();
			onechild=Objects.returnObjInfo(chId);
			//<a href=\"workinJsp?objId="+onechild.get(3)+">>" + onechild.get(1)+ "</a><tr><td><a href=\"workinJsp?objId="+onechild.get(3)+">>" + onechild.get(2)+"</a></td></tr>
			out.print("<tr><td><a href=\"workinJsp?objId="+ Integer.toString(chId)+"\">" + onechild.get(0)+ "</a></td>");
			out.print("<td>" + onechild.get(1)+ "</td>");
			out.print("<td>" + onechild.get(2)+ "</td></tr>");
		}
		%>
	</table>
	<% 
	}
	%>
	<form method="get" action="privateOffice"><button class="btn btn-large" type="submit">privateOffice</button></form>
	<a class="btn btn-large" href="createObject?par=<%=objId%>">create child</a>	
</div>
</div>
</body>
</html>